package com.xnyzc.lhy.didi.controller.order;

import com.xnyzc.lhy.common.component.didi.DiDiUrlConstant;
import com.xnyzc.lhy.common.component.heli.HeLiUrlContant;
import com.xnyzc.lhy.common.entity.DiDiRv;
import com.xnyzc.lhy.common.exception.DiDiException;
import com.xnyzc.lhy.common.penum.EDiDiErrorCode;
import com.xnyzc.lhy.common.util.sign.AttestationTool;
import com.xnyzc.lhy.didi.entity.param.order.CreateOrderParam;
import com.xnyzc.lhy.didi.entity.param.order.OrderDetailParam;
import com.xnyzc.lhy.didi.service.order.OrderCorrelationService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单相关
 * </p>
 *
 * @author wangshuo
 * @since 2019-09-25
 */
@RestController
@RequestMapping("oa/didi/order")
public class OrderCorrelationController {

    @Autowired
    private OrderCorrelationService orderCorrelationService;

    /**
     * 查询订单详情
     *
     * @param orderDetailParam
     * @return
     */
    @ApiOperation(value = "查询订单详情", notes = "查询订单详情")
    @PostMapping(value = "/getOrderDetail")
    public DiDiRv getOrderDetail(@ApiParam(name =
            "orderDetailParam", value = "查询订单详情") @RequestBody OrderDetailParam orderDetailParam) {
        return orderCorrelationService.getOrderDetail(orderDetailParam);
    }

    /**
     * 订单状态查询
     *
     * @param orderDetailParam
     * @return
     */
    @ApiOperation(value = "订单状态查询", notes = "订单状态查询")
    @PostMapping(value = "/getOrderStatus")
    public DiDiRv getOrderStatus(@ApiParam(name =
            "orderDetailParam", value = "订单状态查询") @RequestBody OrderDetailParam orderDetailParam) {
        return orderCorrelationService.getOrderStatus(orderDetailParam);
    }

    /**
     * 下听订单实时账单
     *
     * @param orderDetailParam
     * @return
     */
    @ApiOperation(value = "下听订单实时账单", notes = "下听订单实时账单")
    @PostMapping(value = "/pGetRealTimeFeeDetail")
    public DiDiRv pGetRealTimeFeeDetail(@ApiParam(name =
            "orderDetailParam", value = "下听订单实时账单") OrderDetailParam orderDetailParam) {
        return orderCorrelationService.pGetRealTimeFeeDetail(orderDetailParam);
    }


    /**
     * 创建订单
     *
     * @param
     * @return
     */
    @ApiOperation(value = "创建订单", notes = "创建订单")
    @PostMapping(value = "/getCreateOrder")
    public DiDiRv getCreateOrder(@ApiParam(name =
            "createOrderParam", value = "创建订单") CreateOrderParam createOrderParam) {
        return orderCorrelationService.getCreateOrder(createOrderParam);
    }

    /**
     * 创建订单开发版本
     *
     * @param
     * @return
     */
    @ApiOperation(value = "创建订单开发版本", notes = "创建订单开发版本")
    @PostMapping(value = "/getCreateOrderReal")
    public DiDiRv getCreateOrderReal(@ApiParam(name =
            "createOrderParam", value = "创建订单") CreateOrderParam createOrderParam) {
        if (!AttestationTool.getRequestSign(createOrderParam, createOrderParam.getSign(), DiDiUrlConstant.didiSignReq)) {
            throw DiDiException.create(EDiDiErrorCode.failureOfVerification);
        }
        return orderCorrelationService.getCreateOrderReal(createOrderParam);
    }

    /**
     * 取消订单
     *
     * @param orderDetailParam
     * @return
     */
    @ApiOperation(value = "取消订单", notes = "取消订单")
    @PostMapping(value = "/cancelOrder")
    public DiDiRv cancelOrder(@ApiParam(name =
            "orderDetailParam", value = "取消订单") OrderDetailParam orderDetailParam) {
        if (!AttestationTool.getRequestSign(orderDetailParam, orderDetailParam.getSign(), DiDiUrlConstant.didiSignReq)) {
            throw DiDiException.create(EDiDiErrorCode.failureOfVerification);
        }
        return orderCorrelationService.cancelOrder(orderDetailParam);
    }

    /**
     * 查询订单状态
     *
     * @param orderDetailParam
     * @return
     */
    @ApiOperation(value = "查询订单状态", notes = "查询订单状态")
    @PostMapping(value = "/queryOrderStatus")
    public DiDiRv queryOrderStatus(@ApiParam(name =
            "orderDetailParam", value = "查询订单状态") OrderDetailParam orderDetailParam) {
        if (!AttestationTool.getRequestSign(orderDetailParam, orderDetailParam.getSign(), DiDiUrlConstant.didiSignReq)) {
            throw DiDiException.create(EDiDiErrorCode.failureOfVerification);
        }
        return orderCorrelationService.queryOrderStatus(orderDetailParam);
    }

    /**
     * 账单详情
     *
     * @param orderDetailParam
     * @return
     */
    @ApiOperation(value = "账单详情", notes = "账单详情")
    @PostMapping(value = "/billDetails")
    public DiDiRv billDetails(@ApiParam(name =
            "orderDetailParam", value = "查询订单详情") OrderDetailParam orderDetailParam) {
        if (!AttestationTool.getRequestSign(orderDetailParam, orderDetailParam.getSign(), DiDiUrlConstant.didiSignReq)) {
            throw DiDiException.create(EDiDiErrorCode.failureOfVerification);
        }
        return orderCorrelationService.billDetails(orderDetailParam);
    }

}
